<template>
  <el-card>
    <el-button type="primary" @click="openAddDialog">新增项目</el-button>
    <el-table :data="projectList" style="width: 100%;margin-top:16px;">
      <el-table-column prop="projectName" label="项目名称" />
      <el-table-column prop="projectType" label="项目类型" />
      <el-table-column prop="startDate" label="开始时间" />
      <el-table-column prop="endDate" label="结束时间" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="small" @click="editProject(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="deleteProject(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 新增/编辑弹窗 -->
    <el-dialog v-model="dialogVisible" title="项目编辑">
      <el-form :model="form">
        <el-form-item label="项目名称"><el-input v-model="form.projectName" /></el-form-item>
        <el-form-item label="项目类型"><el-input v-model="form.projectType" /></el-form-item>
        <el-form-item label="开始时间"><el-date-picker v-model="form.startDate" /></el-form-item>
        <el-form-item label="结束时间"><el-date-picker v-model="form.endDate" /></el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible=false">取消</el-button>
        <el-button type="primary" @click="saveProject">保存</el-button>
      </template>
    </el-dialog>
  </el-card>
</template>
<script setup>
import { ref } from 'vue';
const projectList = ref([
  { projectName: '纵向课题A', projectType: '国家级', startDate: '2023-01-01', endDate: '2024-01-01' },
  { projectName: '横向课题B', projectType: '企业合作', startDate: '2022-05-01', endDate: '2023-05-01' }
]);
const dialogVisible = ref(false);
const form = ref({});
const openAddDialog = () => {
  form.value = {};
  dialogVisible.value = true;
};
const editProject = (row) => {
  form.value = { ...row };
  dialogVisible.value = true;
};
const saveProject = () => {
  // 保存逻辑，调用后端API
  dialogVisible.value = false;
};
const deleteProject = (id) => {
  // 删除逻辑，调用后端API
};
</script> 